<!--
 * @Author: jswang
 * @Date: 2021-08-25 13:36:39
 * @LastEditTime: 2021-08-25 13:56:29
-->
<template>
  <el-dropdown trigger="click" @command="changeClanguage">
    <!-- 这里必须加一个div 让他布局,应为 svg-icon 是一个行内元素-->
    <div>
      <svg-icon icon-class="language" />
    </div>
    <!-- 下拉图标 -->
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="this.$i18n.locale === 'zh'">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="this.$i18n.locale === 'en'">en</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookie from 'js-cookie'
export default {
  methods: {
    changeClanguage(type) {
      // 先写入到 cookie 中  lang中会去读取
      Cookie.set('language', type)
      this.$i18n.locale = type
      this.$message.success('切换语言成功')
    }
  }
}
</script>

<style>

</style>
